package com.rbmq.demo.test.simplelist;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @version 1.0
 * @Author: 许啸林
 * @Date: 2021/6/15 16:27
 */
public class Customer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("47.97.229.240");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/ems");
        connectionFactory.setUsername("admin2");
        connectionFactory.setPassword("123");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("lcj", true, false, false, null);
        // 设置消息消费者
        // p1 消息队列名称
        // p2 消息自动确认
        // p3 消费回调方法
        channel.basicConsume("lcj", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("=============MSG: " + new String(body));
            }
        });
    }
}
